import { app, BrowserWindow } from "electron";
import * as path from "path";

/**
 * Creates window
 */
function createWindow() {
  // Create the browser window.
  const mainWindow = new BrowserWindow({
    height: 600,
    webPreferences: {
      /** 12.00 以后版本会默认关闭,关闭后无法正常使用process函数，需要后台调用 */
      contextIsolation: false,
      nodeIntegration: true
    },
    width: 800
  });
  console.log(path.join(__dirname, "main.html"));
  mainWindow.loadFile("main.html");
  mainWindow.webContents.openDevTools();
  console.log(process.versions.node);
}

app.whenReady().then(createWindow);

app.on("window-all-closed", () => {
  if (process.platform !== "darwin") {
    app.quit();
  }
});

app.on("activate", () => {
  console.log("activate");
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});
